package com.fhzn.boss.web.request;

import com.fhzn.boss.entity.App;
import com.fhzn.boss.enums.CommonStatusEnum;
import com.fhzn.commons.toolkit.exception.BuzException;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

/**
 * @author 老顾
 * @apiNote
 * @since 2024/1/3
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class AppOpRequest extends BaseRequest {

    private Integer id;

    private String name;

    private String code;

    private Integer status;

    private String comment;

    private String creator;

    private String modifier;

    private String owners;


    public void checkAdd() {
        if (StringUtils.isBlank(code)) {
            throw new BuzException("code不能为空");
        }
        this.checkCommon();
    }

    public void checkUpdate() {
        if (id == null) {
            throw new BuzException("id不能为空");
        }
        this.checkCommon();
    }

    public void checkCommon() {

        this.checkBaseParams();

        if (StringUtils.isBlank(name)) {
            throw new BuzException("name不能为空");
        }

        if (status == null || !CommonStatusEnum.contains(status)) {
            throw new BuzException("状态位不正确");
        }

    }


    /**
     * 生成发送服务端对象
     *
     * @return app
     */
    @Override
    public App genServiceParam() {
        App app = new App();
        app.setId(this.getId());
        app.setName(this.getName());
        app.setCode(this.getCode());
        app.setStatus(this.getStatus());
        app.setComment(this.getComment());
        app.setCreator(this.getHandler());
        app.setModifier(this.getHandler());
        return app;
    }
}
